using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using LGE;

namespace GGJ2014
{
    public class GGJ2014 : Game
    {
        public GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public static bool isDebugMode = false;
        public static SpriteFont Font;

        public static Dictionary<String, float> Volume = new Dictionary<string, float>() { { "BGM", 1f }, { "SFX", 1f } };

        public GGJ2014()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            Engine.InitGraphicsMode(graphics, 1280, 720, false);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //Font = Content.Load<SpriteFont>("Fonts\\GrungeOverlords34");
            Audio.Init("Content\\Audio\\GGJ2014.xgs", "Content\\Audio\\Wave Bank.xwb", "Content\\Audio\\Sound Bank.xsb");
            Engine.Init(this, new PlayScreen());
            Audio.audioEngine.GetCategory("BGM").SetVolume(Volume["BGM"]);
            Audio.audioEngine.GetCategory("SFX").SetVolume(Volume["SFX"]);
            //GameScreenManager.SetLoadScreenBG(Engine.Load<Texture2D>("Images\\bg_loadingscreen"));
            KeyMap.Init();
            //LoadTextures();
        }

        protected override void Update(GameTime gameTime)
        {
            GameScreenManager.Update(gameTime);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            GameScreenManager.Draw(gameTime, spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }

    public static class KeyMap
    {
        public static String Enter = "Enter";
        public static String DebugMode = "DebugMode";

        public static String Up = "Up";
        public static String Down = "Down";
        public static String Left = "Left";
        public static String Right = "Right";

        public static String Action = "Action";
        public static String ScrollLeft = "ScrollLeft";
        public static String ScrollRight = "ScrollRight";

        public static void Init()
        {
            Input.RegisterKeyMapping(Enter, Keys.Enter, Buttons.Start);
            Input.RegisterKeyMapping(DebugMode, Keys.Q, Buttons.LeftTrigger);

            Input.RegisterKeyMapping(Up, Keys.Up, Buttons.LeftThumbstickUp);
            Input.RegisterKeyMapping(Down, Keys.Down, Buttons.LeftThumbstickDown);
            Input.RegisterKeyMapping(Left, Keys.Left, Buttons.LeftThumbstickLeft);
            Input.RegisterKeyMapping(Right, Keys.Right, Buttons.LeftThumbstickRight);

            Input.RegisterKeyMapping(Action, Keys.Space, Buttons.A);
            Input.RegisterKeyMapping(ScrollLeft, Keys.A, Buttons.LeftShoulder);
            Input.RegisterKeyMapping(ScrollRight, Keys.S, Buttons.RightShoulder);
        }
    }


#if WINDOWS || XBOX
    static class Program
    {
        static void Main(string[] args)
        {
            using (GGJ2014 game = new GGJ2014())
            {
                game.Run();
            }
        }
    }
#endif
}
